package com.bytecollege.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bytecollege.mapper.AdminMapper;
import com.bytecollege.mapper.AremarkMapper;
import com.bytecollege.model.Aremark;
import com.bytecollege.service.AremarkService;
import com.bytecollege.vo.AremarkVo;
import com.bytecollege.vo.ArticleVo;
import com.bytecollege.vo.MyAreMarkVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName: AremarkMapper
 * @Description:
 * @Author: Sun
 * @Date: 2022/10/18 21:03
 */

@Service
public class AremarkServiceImpl extends ServiceImpl<AremarkMapper, Aremark> implements AremarkService {
    @Autowired
    AdminMapper adminMapper;
    @Autowired
    AremarkMapper aremarkMapper;



    /**
     * 删除评论
     * @param id
     * @return
     */
    public int delAremarkById(Integer id){
        return aremarkMapper.deleteById(id);
    }

    /**
     * 添加讨论区留言
     * @param aremark
     * @return
     */
    public int addAremark(Aremark aremark) {return aremarkMapper.insert(aremark);}

    /**
     * 查找对应文章的评论
     * @param articleId
     * @return
     */
    public IPage<AremarkVo> getAremarkByArticleId(Page<AremarkVo> page,Integer articleId) {
        QueryWrapper<AremarkVo> aremarkVoQueryWrapper = new QueryWrapper<>();
        aremarkVoQueryWrapper.eq("ar.article_id",articleId);
        return aremarkMapper.getAremarkByArticleId(page,aremarkVoQueryWrapper);
    }

    /**
     * 用户主页对应的所有评论
     * @param page
     * @param userId
     * @return
     */
    public List<MyAreMarkVO> getAllAremark(Page<MyAreMarkVO> page, Integer userId) {
        return aremarkMapper.getAremarkList(page,userId);
    }
}